package com.gitee.wsl.ext.string


// takeIfNotEmpty ------------------------------------------------------------------------------------------------------

/** Returns this character sequence if it [isNotEmpty] or `null`, if it is. */
@Suppress("NOTHING_TO_INLINE")
 inline fun CharSequence.takeIfNotEmpty(): CharSequence? = takeIf { it.isNotEmpty() }

/** Returns this string if it [isNotEmpty] or `null`, if it is. */
@Suppress("NOTHING_TO_INLINE")
 inline fun String.takeIfNotEmpty(): String? = takeIf { it.isNotEmpty() }


// takeIfNotBlank ------------------------------------------------------------------------------------------------------

/** Returns this character sequence if it [isNotBlank] or `null`, if it is. */
@Suppress("NOTHING_TO_INLINE")
 inline fun CharSequence.takeIfNotBlank(): CharSequence? = takeIf { it.isNotBlank() }

/** Returns this string if it [isNotBlank] or `null`, if it is. */
@Suppress("NOTHING_TO_INLINE")
 inline fun String.takeIfNotBlank(): String? = takeIf { it.isNotBlank() }


// takeUnlessEmpty -----------------------------------------------------------------------------------------------------

/** Returns this character sequence if it [isNotEmpty] or `null`, if it is. */
@Suppress("NOTHING_TO_INLINE")
 inline fun CharSequence.takeUnlessEmpty(): CharSequence? = takeUnless { it.isEmpty() }

/** Returns this string if it [isNotEmpty] or `null`, if it is. */
@Suppress("NOTHING_TO_INLINE")
 inline fun String.takeUnlessEmpty(): String? = takeUnless { it.isEmpty() }


// takeUnlessBlank -----------------------------------------------------------------------------------------------------

/** Returns this character sequence if it [isNotBlank] or `null`, if it is. */
@Suppress("NOTHING_TO_INLINE")
 inline fun CharSequence.takeUnlessBlank(): CharSequence? = takeUnless { it.isBlank() }

/** Returns this string if it [isNotBlank] or `null`, if it is. */
@Suppress("NOTHING_TO_INLINE")
 inline fun String.takeUnlessBlank(): String? = takeUnless { it.isBlank() }
